import { defineStore } from "pinia";
import request from "../utils/request.js";
export const useStar = defineStore('star', {
  state: () => {
    return {
      list:[],
    }
  },
  actions: {
   async initStarList(){
    let res = await request.get('/star')
    console.log(res);
    this.list = res.data.data
   },
   async starPost(payload){
    let res = await request.post('/star',payload)// 更新数据库
    console.log(res);
    if(res.data.code==1){
        this.list.push(payload)// 本地数据更新
    }
   }
  },
  getters: { // 计算属性
   filterList(){
    let arr = this.list.filter(item=>item.age>20)
    return arr
   } 
  }
})